// 路由配置信息
// 引入路由组件
// 引入二级路由组件

export default [{
        path: '/center',
        component: () =>
            import ('@/pages/Center'),
        name: 'Center',
        // 二级路由组件
        children: [{
            path: 'myorder',
            component: () =>
                import ('@/pages/Center/myOrder'),
        }, {
            path: 'grouporder',
            component: () =>
                import ('@/pages/Center/groupOrder'),
        }, {
            path: '/center',
            redirect: '/center/myorder'
        }],
        meta: {
            show: true
        }
    }, {
        path: '/paysuccess',
        component: () =>
            import ('@/pages/PaySuccess'),
        name: 'PaySuccess',
        // beforeEnter: (to, from, next) => {
        //     // ...
        //     if (from.path == '/pay') {
        //         next()
        //     } else {
        //         next(false)
        //     }
        // },
        meta: {
            show: true
        }
    }, {
        path: '/pay',
        component: () =>
            import ('@/pages/Pay'),
        name: 'Pay',
        beforeEnter: (to, from, next) => {
            // ...
            if (from.path == '/trade') {
                next()
            } else {
                next(false)
            }
        },
        meta: {
            show: true
        }
    }, {
        path: '/trade',
        component: () =>
            import ('@/pages/Trade'),
        name: 'Trade',
        // 路由独享守卫
        beforeEnter: (to, from, next) => {
            // ...
            if (from.path == '/shopcart') {
                next()
            } else {
                // 中断当前导航 回到from路由地址
                next(false)
            }
        },
        meta: {
            show: true
        }
    }, {
        path: '/shopcart',
        component: () =>
            import ('@/pages/ShopCart'),
        name: 'ShopCart',
        meta: {
            show: true
        }
    }, {
        path: '/addcartsuccess',
        component: () =>
            import ('@/pages/AddCartSuccess'),
        name: 'addcartsuccess',
        meta: {
            show: true
        }
    }, {
        path: '/detail/:skuId',
        component: () =>
            import ('@/pages/Detail'),
        meta: {
            show: true
        }
    }, {
        path: '/home',
        component: () =>
            import ('@/pages/Home'),
        meta: {
            show: true
        }
    }, {
        path: '/login',
        component: () =>
            import ('@/pages/Login'),
        meta: {
            show: false
        }
    }, {
        path: "/search/:keyword?",
        // ?占位符 保持params参数可传可不传
        component: () =>
            import ('@/pages/Search'),
        name: 'search',
        meta: {
            show: true
        },
        // 路由组件能否传递props 
        // 1布尔值类型  只能传递params参数
        // props: true
        // 2对象写法 额外给路由传递一些参数
        // props: {
        //     a: 1,
        //     b: 2
        // }
        // 3函数写法
        props: ($route) => {
            return {
                keyword: $route.params.keyword,
                // k: $route.query.k.toUpperCase
                k: $route.query.k
            }
        }
    }, {
        path: '/register',
        component: () =>
            import ('@/pages/Register'),
        meta: {
            show: false
        }
    },
    // 重定向
    {
        path: '/',
        redirect: '/home'
    }
]